package com.bom.boot.easy.entity;

import cn.hutool.core.util.StrUtil;
import com.bom.boot.easy.core.comment.Comment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Nationalized;

import javax.persistence.*;
import java.io.Serializable;

@Data
@Entity(name = "core_xml")
@Comment("mybatis查询配置sql")
@IdClass(XmlEntity.XmlId.class)
public class XmlEntity {
    @Id
    private String ds;

    @Id
    private String key;

    @Column(columnDefinition = "TEXT")
    @Comment("xml片段")
    private String xmlClip;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class XmlId implements Serializable {
        @Comment("数据库名称")
        private String ds;
        @Comment("查询名称")
        private String key;

        public String addr() {
            return ds + "." + key;
        }

        public String resultType() {
            return StrUtil.toCamelCase(ds + "_" + key + "_resultType");
        }
    }
}
